/**
 * TorrentJEDI
 * 		Torrent Java Episode Download Interface
 */
package torrentjedi.net;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author Alper Kokmen
 *
 */
public class RSSFetcher {
	private URL url;
	private String data;
	
	public RSSFetcher(String url) {
		try {
			this.url = new URL(url);
			this.data = new String("");
		} catch (MalformedURLException e) {
			System.out.println("ERROR@TorrentJEDI:TorrentSourceFetcher TorrentSourceFetcher url cannot be parsed");
		}
	}
	
	public void fetchRSS() {
		InputStream inputStream = null;
		
		try {
			inputStream = getUrl().openStream();
			DataInputStream dataInputStream = new DataInputStream(inputStream);
			
			while ((data = dataInputStream.readUTF()) != null) {
//				System.out.println("DEBUG@TorrentJEDI:TorrentSourceFetcher fetchRSS [" + getData() + "]");
			}
			
		} catch (IOException e) {
			System.out.println("ERROR@TorrentJEDI:TorrentSourceFetcher fetchRSS cannot open the stream");
		} finally {
			try {
				inputStream.close();
			} catch (IOException e) {
				System.out.println("ERROR@TorrentJEDI:TorrentSourceFetcher fetchRSS cannot close the stream");	
			}
		}
	}

	/**
	 * @return the url
	 */
	public URL getUrl() {
		return url;
	}

	/**
	 * @param url the url to set
	 */
	public void setUrl(URL url) {
		this.url = url;
	}

	/**
	 * @return the data
	 */
	public String getData() {
		return data;
	}

	/**
	 * @param data the data to set
	 */
	public void setData(String data) {
		this.data = data;
	}
	
}
